package com.ruoyi.lobby.service.impl;

import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.ruoyi.common.core.domain.AjaxResult;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.lobby.mapper.VettingMapper;
import com.ruoyi.lobby.domain.Vetting;
import com.ruoyi.lobby.service.IVettingService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 审批Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-11-14
 */
@Service
public class VettingServiceImpl implements IVettingService 
{
    @Autowired
    private VettingMapper vettingMapper;

    /**
     * 查询审批
     * 
     * @param id 审批主键
     * @return 审批
     */
    @Override
    public Vetting selectVettingById(Long id)
    {
        return vettingMapper.selectVettingById(id);
    }

    /**
     * 查询审批列表
     * 
     * @param vetting 审批
     * @return 审批
     */
    @Override
    public List<Vetting> selectVettingList(Vetting vetting)
    {
        return vettingMapper.selectVettingList(vetting);
    }

    /**
     * 新增审批
     * 
     * @param vetting 审批
     * @return 结果
     */
    @Override
    public int insertVetting(Vetting vetting) { return vettingMapper.insertVetting(vetting); }

    /**
     * 修改审批
     * 
     * @param vetting 审批
     * @return 结果
     */
    @Override
    public int updateVetting(Vetting vetting)
    {
        // 获取当前日期的午夜时间（00:00:00）
        LocalDate currentDate = LocalDate.now();
        ZonedDateTime startOfDay = currentDate.atStartOfDay(ZoneId.systemDefault());

        // 将ZonedDateTime转换为Date（这里使用了系统默认时区，但最好明确指定时区）
        Date date = Date.from(startOfDay.toInstant());

        vetting.setPassTime(date);
        vettingMapper.updatePass(vetting);
        return vettingMapper.updateVetting(vetting);
    }


    /**
     * 批量删除审批
     * 
     * @param ids 需要删除的审批主键
     * @return 结果
     */
    @Override
    public int deleteVettingByIds(Long[] ids)
    {
        return vettingMapper.deleteVettingByIds(ids);
    }

    /**
     * 删除审批信息
     * 
     * @param id 审批主键
     * @return 结果
     */
    @Override
    public int deleteVettingById(Long id)
    {
        return vettingMapper.deleteVettingById(id);
    }
}
